var current_chat_height = 0; function dragElement(elmnt, event_element) { let pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0; if (document.getElementById(event_element)) { /* if present, the header is where you move the DIV from:*/ document.getElementById(event_element).onmousedown = dragMouseDown; } else { /* otherwise, move the DIV from anywhere inside the DIV:*/ elmnt.onmousedown = dragMouseDown; } function dragMouseDown(e) { $(".frameOverlay").show(); e = e || window.event; e.preventDefault(); // get the mouse cursor position at startup: pos3 = e.clientX; pos4 = e.clientY; document.onmouseup = closeDragElement; // call a function whenever the cursor moves: document.onmousemove = elementDrag; } function elementDrag(e) { e = e || window.event; e.preventDefault(); // calculate the new cursor position: pos1 = pos3 - e.clientX; pos2 = pos4 - e.clientY; pos3 = e.clientX; pos4 = e.clientY; const height = window.innerHeight; const width = window.innerWidth; const chat_width = $('#chat-widget-container').width(); const chat_height = $('#chat-widget-container').height(); const new_top = elmnt.offsetTop - pos2; const new_left = elmnt.offsetLeft - pos1; current_chat_height = $('#chat-widget-container').height(); if (new_top >= 0 && new_top <= (height - chat_height) && new_left >= -16 && new_left <= (width - chat_width)) { // set the element's new position: elmnt.style.top = `${new_top}px`; elmnt.style.left = `${new_left}px`; } } function closeDragElement() { /* stop moving when mouse button is released:*/ document.onmouseup = null; document.onmousemove = null; $(".frameOverlay").hide(); } } const onVisibilityChanged = ({ visibility }) => { switch (visibility) { case "maximized": $("#chat-widget-container").addClass("open"); document.querySelector('#chat-widget-container').classList.remove('gdpr_visible'); $(".drag-top").css("display", "flex"); if (current_chat_height > 0) { $('#chat-widget-container').height(current_chat_height); } setDragResizeEvents(); break; case "minimized": $("#chat-widget-container").removeClass("open"); $(".drag-top").hide(); $(document).off('mouseup').off('mousemove'); $('#resize_chat').off('mousedown'); gdprVisibilityChange(); break; case "hidden": break; } } const arrow_vertical = ``; const arrows = ``; const onReady = ({ state, customerData }) => { $('#chat-widget-container').prepend( `